﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2013-03-26 16:44:33Z</CreationDate>
</File>
*/
#endregion

using System;
using System.IO.IsolatedStorage;
using System.Threading.Tasks;

using Outcoder.Concurrency;

#if WPF
using IsolatedStorageSettings = System.IO.IsolatedStorage.IsolatedStorageSettingsWpf;
#endif

namespace Outcoder.Services.Implementation
{
	public class LocalSettingsStore : ISettingsStore
	{
		public bool TryGetValue(string key, Type settingType, out object value)
		{
			return IsolatedStorageSettings.ApplicationSettings.TryGetValue(key, out value);
		}

		public bool Contains(string key)
		{
			return IsolatedStorageSettings.ApplicationSettings.Contains(key);
		}

		public bool Remove(string key)
		{
			return IsolatedStorageSettings.ApplicationSettings.Remove(key);
		}

		public Task Clear()
		{
			IsolatedStorageSettings.ApplicationSettings.Clear();

			return TaskUtility.CreateTaskWithResult();
		}

		public Task Save()
		{
			IsolatedStorageSettings.ApplicationSettings.Save();

			return TaskUtility.CreateTaskWithResult();
		}

		public object this[string key]
		{
			get
			{
				return IsolatedStorageSettings.ApplicationSettings[key];
			}
			set
			{
				IsolatedStorageSettings.ApplicationSettings[key] = value;
			}
		}

		public SettingsStoreStatus Status => SettingsStoreStatus.Ready;
	}
}
